Accusoft.TwainPro9.ActiveX
Transfer & Save Images

Once a scanning session has been initiated by calling StartSession, one or more images can be scanned by the Data Source, transferred from the Data Source to the application, and saved by the application to file or memory.

Check for Pending Transfers

Prior to initiating a transfer of a scanned image from the Data Source to the application, TwainPRO™ raises a PreScan event. This event is the trigger to check the pending transfers. The PendingXfers property will contain the number of images the Data Source has ready for transfer. If the Data Source doesn't know how many images are ready for transfer, PendingXfers will be equal to -1. TWAIN Data Sources with Automatic Document Feeders (ADF) will return PendingXfers equal to -1. Such devices will transfer images until the feeder is empty.

Transfer Images from Data Source to Application

Upon proceeding from the PreScan event, pending images will be transferred from the Data Source to the application.

Save Scanned Images

When the transfer of each image is complete, TwainPRO raises a PostScan event. This event is the trigger to save the image to file or memory.

During the PostScan event, the hDIB property contains the latest scanned image. This information will be lost once the transfer of another image is initiated. Therefore, the application must select a method for saving the scanned image prior to initiating the next scan.

ImagXpress.hDIB = TwainPRO.hDIB

Finish Scanning

Upon exiting the Post-Scan event, the acquisition process continues, by triggering another Pre-Scan event. At any point during the Pre-Scan, Image Transfer, or Post-Scan states, the application can call CancelPendingXfers to terminate the scanning session. Alternatively, setting the Cancel parameter in the Pre-Scan or Post-Scan events will also terminate the scanning session.

VB Example
Copy Code
' This code demonstrates how to save to a multi-page file
Private Sub TwainPRO1_PostScan(Cancel As Boolean)
' When scanning from a document feeder,
' the PostScan event will fire after each page is scanned.
TwainPRO1.SaveTIFFCompression = TWTIF_CCITTFAX4
TwainPRO1.SaveMultiPage = True
TwainPRO1.SaveFile App.Path & "\multiPage.tiff"
End Sub 

 

VB Example
Copy Code
' This code demonstrates how to start a TWAIN session and place each image into a Picture control array
Private Sub cmdStart_Click()
scancount = 0
TwainPRO1.StartSession
End Sub
Private Sub TwainPRO1_PostScan(Cancel as Boolean)
PictureBox1(scancount).Picture = TwainPRO1.Picture
scancount = scancount + 1
End Sub 

 

Example
Copy Code
' This code demonstrates how to successfully negotiate the transfer mode and to transfer data in a compressed format
' Set the Transfer Mode to buffered memory mode
TwainPRO.TransferMode = TWSX_MEMORY
TwainPRO.OpenSession
If (TwainPRO.TransferMode = TWSX_MEMORY) Then
TwainPRO.CapTypeOut = TWON_ONEVALUE
TwainPRO.Capability = TP_Capability_UseCapAdvanced
TwainPRO.CapAdvanced = ICAP_COMPRESSION
If TwainPRO.CapSupported Then
TwainPRO.CapValueOut = TWCP_JPEG
TwainPRO.SetCapOut

'Normally then you would negotiate the ICAP_JPEGPIXELTYPE
'and ICAP_JPEGQUALITY capabilities.
'Using the defaults for both of these values
End If
End If
TwainPRO.StartSession

' A simple typical PostScan event handler.
Private Sub TwainPRO_PostScan(Cancel As Boolean)

Dim hImage As Long

On Error GoTo psError

' Need to check the Compression type to see
' if we are transferring a DIB or we are
' transferring compressed data.
If TwainPRO.ICompression = TWCP_NONE Then
hImage = TwainPRO.hDIB
If (hImage <> 0) Then
ImgXpr.hDIB = hImage
End If
Else
hImage = TwainPRO.hImage
If (hImage <> 0) Then
ImgXpr.LoadBuffer (hImage)
End If
End If
Exit Sub

psError:
GetError
Cancel = True
End Sub 

 

See Also

 

 


©2017. Accusoft Corporation. All Rights Reserved.

Send Feedback